#!/usr/bin/env bash

#
# Copyright 2018 Analytics Zoo Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

SCRIPT_DIR=$(dirname ${BASH_SOURCE[0]})
export DL_PYTHON_HOME="$(cd ${SCRIPT_DIR}/../; pwd)"

header="Copyright 2018 Analytics Zoo Authors"

echo "Checking Analytics Zoo license for Python files..."
# Excluding tfpark/inception/nets, because they are migrated from TensorFlow
find $DL_PYTHON_HOME ! -name "pep8-1.7.0.py" -name "*.py" | grep -v "tfpark/inception/nets/" \
| while read -d $'\n' file
do
    if ! (grep -qF "$header" "$file");
    then
        echo "No license or wrong license in $file. Please add the correct license."
        exit 1
    fi
done
